package com.tzm.gaflow.controller;


import com.tzm.gaflow.web.controller.BaseController;
import com.tzm.gaflow.web.domain.Result;
import com.tzm.gaflow.web.util.ResultUtils;
import com.tzm.gaflow.dto.GaFlowDTO;
import com.tzm.gaflow.entity.GaFlowGrant;
import com.tzm.gaflow.service.GaFlowManagerService;
import com.tzm.gaflow.vo.GaFlowInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/gaFlow")
@Api(description = "通用流程管理接口", tags = {"通用流程管理"})
public class GaFlowController extends BaseController {

    @Autowired
    GaFlowManagerService gaFlowManagerService;

    /**
     * 根据业务类型获取流程节点信息
     */
    @GetMapping("/listFlowByBussinesType/{bussinesType}")
    @ApiOperation(notes = "根据业务类型查询流程节点信息", value = "listFlowByBussinesType")
    public Result<List<GaFlowInfoVO>> listFlowByBussinesType(@PathVariable String bussinesType) {
        List<GaFlowInfoVO> gaFlowInfoVOS = gaFlowManagerService.listFlowByBussinesType(bussinesType);
        return ResultUtils.ok(gaFlowInfoVOS);
    }

    /**
     * 根据流程ID获取流程节点权限信息
     */
    @GetMapping("/listGrantByFlowId/{flowId}")
    @ApiOperation(notes = "根据流程ID获取流程节点权限信息", value = "listGrantByFlowId")
    public Result<List<GaFlowGrant>> listGrantByFlowId(@PathVariable String flowId) {
        List<GaFlowGrant> gaFlowGrants = gaFlowManagerService.listGrantByFlowId(flowId);
        return ResultUtils.ok(gaFlowGrants);
    }

    /**
     * 根保存流程信息
     */
    @PostMapping("/saveFlow")
    @ApiOperation(notes = "保存流程信息", value = "saveFlow")
    public Result<String> saveFlow(@RequestBody GaFlowDTO gaFlowDTO) {
        gaFlowManagerService.saveFlow(gaFlowDTO);
        return ResultUtils.ok("保存流程信息成功！");
    }

}
